package com.cmict.data.infra.dal.mysql.rdbcolumn;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cmict.data.framework.common.pojo.PageResult;
import com.cmict.data.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cmict.data.framework.mybatis.core.mapper.BaseMapperX;
import com.cmict.data.infra.dal.dataobject.rdbcolumn.RdbColumnDO;
import com.cmict.data.infra.dal.dataobject.rdbtabledraft.RdbTableDraftDO;
import org.apache.ibatis.annotations.Mapper;
import com.cmict.data.infra.controller.admin.rdbcolumn.vo.*;

/**
 * 常用字段 Mapper
 *
 * @author awesome1114
 */
@Mapper
public interface RdbColumnMapper extends BaseMapperX<RdbColumnDO> {

    default PageResult<RdbColumnDO> selectPage(RdbColumnPageReqVO reqVO) {
        QueryWrapper<RdbColumnDO> queryWrapper=new QueryWrapper<>();
        if(reqVO.getKeyword()!=null){
            queryWrapper.lambda().and(qw -> qw.like(RdbColumnDO::getColumnName, reqVO.getKeyword())
                    .or().like(RdbColumnDO::getColumnComment, reqVO.getKeyword()));
        }
        queryWrapper.lambda().orderByDesc(RdbColumnDO::getCreateTime);
        return selectPage(reqVO,queryWrapper);
    }

    default List<RdbColumnDO> selectList(RdbColumnExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<RdbColumnDO>()
                .likeIfPresent(RdbColumnDO::getColumnName, reqVO.getColumnName())
                .eqIfPresent(RdbColumnDO::getColumnComment, reqVO.getColumnComment())
                .eqIfPresent(RdbColumnDO::getColumnType, reqVO.getColumnType())
                .eqIfPresent(RdbColumnDO::getColumnLength, reqVO.getColumnLength())
                .betweenIfPresent(RdbColumnDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(RdbColumnDO::getId));
    }

   default List<RdbColumnDO> getRdbColumnList(String keyword){
       QueryWrapper<RdbColumnDO> queryWrapper=new QueryWrapper<>();
       if(keyword != null){
           queryWrapper.lambda().and(qw -> qw.like(RdbColumnDO::getColumnName, keyword)
                   .or().like(RdbColumnDO::getColumnComment, keyword));
       }
       queryWrapper.lambda().orderByDesc(RdbColumnDO::getCreateTime);
       return   selectList(queryWrapper);
   }
}
